﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>客户列表管理</title>
    <#include "../common/link.ftl">

    <script>
        $(function () {

            //新增或编辑按钮的点击事件
            $('.btn-input').click(function () {
                //先清除之前模态框的数据
                $('#editModal input').val('')
                //给编辑显示的模态框回显数据
                //获取事件源绑定的数据 用data方法可以很方便的获取data-* 开头的属性的数据
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    $("#editForm input[name=id]").val(json.id);
                    $("#editForm input[name=name]").val(json.name);
                    $("#editForm input[name=age]").val(json.age);
                    $("#editForm input[name=gender]").val(json.gender);
                    $("#editForm input[name=tel]").val(json.tel);
                    $("#editForm input[name=qq]").val(json.qq);
                    $("#editForm select[name='job.id']").val(json.jobId);
                    $("#editForm select[name='source.id']").val(json.sourceId);
                }
                //打开模态框
                $('#editModal').modal('show');


                //保存操作
                $('.btn-insert').click(function () {
                    //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                    $("#editForm").ajaxSubmit(function (data) {
                        handlerMessage(data)
                    })
                })

            })

            var $editForm = $("#editForm");
            $editForm.bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    tel: { // tel 属性值
                        validators: {
                            notEmpty: { // 非空校验
                                message: '手机号码不能为空！'
                            },
                            stringLength: { // 长度校验
                                min: 2,
                                max: 16,
                                message: '用户名长度 %s ~ %s 个字符！'
                            },
                            remote: { //远程验证
                                type: 'post',//请求方式
                                url: '/customer/checkTel.do',//请求路径
                                data: function () {
                                    var data = {
                                        id: $("#id").val()
                                    }
                                    return data;
                                },
                                message: '该手机号码已存在',//验证不通过时返回的错误信息
                                delay: 1000,//一秒后发送一次请求
                            },
                        }
                    },
                }
                //表单所有数据验证通过后执行该方法
            }).on('success.form.bv', function (e) {
                // 禁止原本的表单提交 Prevent form submission
                e.preventDefault();
                // 使用表单异步提交
                $('#editForm').ajaxSubmit(function (data) {
                    if (data.success) {
                        $.messager.confirm('温馨提示', data.msg, function () {
                            window.location.href = '/customer/potentialList.do';
                        });
                    } else {
                        $.messager.alert('温馨提示', data.msg);
                    }
                });
            });

        })
    </script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="customer"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>客户列表管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/customer/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">

                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                               placeholder="请输入姓名/手机号码">
                    </div>

                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                        <div class="form-group">
                            <label for="dept"> 销售人:</label>
                            <select class="form-control" id="seller" name="sellerId">
                                <option value="-1">全部</option>
                                <#list sellers as seller>
                                    <option value="${(seller.id)!}">${(seller.name)!}</option>
                                </#list>
                            </select>
                            <script>
                                $("#seller option[value='${(qo.sellerId)!}']").prop("selected", true);
                            </script>
                        </div>
                    </@shiro.hasAnyRoles>

                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                        <div class="form-group">
                            <label for="dept"> 状态:</label>
                            <select class="form-control" id="status" name="status">
                                <option value="-1">全部</option>
                                <#list status as status>
                                    <option value="${(status.status)!}">${(status.statusName)!}</option>
                                </#list>
                            </select>
                            <script>
                                $("#status option[value='${(qo.status)!}']").prop("selected", true);
                            </script>
                        </div>
                    </@shiro.hasAnyRoles>

                    <button id="btn_query" class="btn btn-primary">
                        <span class="glyphicon glyphicon-search"></span>
                        查询
                    </button>
                   <#-- <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>-->
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>名字</th>
                            <th>电话</th>
                            <th>qq</th>
                            <th>职业</th>
                            <th>来源</th>
                            <th>销售人员</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                            <#list result.list as customer>
                                <tr>
                                    <td>${customer_index+1}</td>
                                    <td>${customer.name!}</td>
                                    <td>${customer.tel!}</td>
                                    <td>${customer.qq!}</td>
                                    <td>${(customer.job.title)!}</td>
                                    <td>${(customer.source.title)!}</td>
                                    <td>${(customer.seller.name)!}</td>
                                    <td>${customer.statusName!}</td>
                                    <td>
                                        <#--<a href="#"
                                           class="btn btn-info btn-xs btn-input" data-json='${customer.json}'>
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>-->
                                    </td>
                                </tr>
                            </#list>
                    </table>
                    <!--分页-->
                <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<#--客户编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title inputTitle">客户编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="" name="id" id="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"
                                   placeholder="请输入客户姓名"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户年龄：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="age"
                                   placeholder="请输入客户年龄"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户性别：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="gender">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户电话：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="tel"
                                   placeholder="请输入客户电话"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户QQ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="qq"
                                   placeholder="请输入客户QQ"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户工作：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="job.id" name="job.id">
                                <#list jobs as j>
                                    <option value="${j.id}">${j.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户来源：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="source.id">
                                <#list sources as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>

                <#-- <div class="form-group">
                     <label class="col-sm-3 control-label">销售人员：</label>
                     <div class="col-sm-6">
                         <select class="form-control" name="seller.id">
                             <#list sellers as e>
                                 <option value="${e.id}">${e.name}</option>
                             </#list>
                         </select>
                     </div>
                 </div>-->

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-insert">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
